package com.situ.web.service.impl;

import com.situ.web.dao.IBanjiDao;
import com.situ.web.dao.impl.BanjiDaoImpl;
import com.situ.web.pojo.entity.Banji;
import com.situ.web.pojo.query.BanjiQuery;
import com.situ.web.pojo.vo.BanjiCountVO;
import com.situ.web.service.IBanjiService;
import com.situ.web.util.LayUITableResult;

import java.util.List;

public class BanjiServiceImpl implements IBanjiService {
    private IBanjiDao banjiDao = new BanjiDaoImpl();

    @Override
    public List<Banji> selectAll() {
        return banjiDao.selectAll();
    }

    @Override
    public List<BanjiCountVO> selectBanjiCount() {
        return banjiDao.selectBanjiCount();
    }


    @Override
    public LayUITableResult selectByPage(BanjiQuery banjiQuery){
        List<Banji> list = banjiDao.selectByPage(banjiQuery);

        int totalCount = banjiDao.selectTotalCount(banjiQuery);

        return  LayUITableResult.ok(totalCount, list);
    }
    /*@Override
    public LayUITableResult selectByPage(BanjiQuery banjiQuery) {
        int offset = (banjiQuery.getPage()-1) * banjiQuery.getLimit();
        List<Banji> list = banjiDao.selectByPage(offset,banjiQuery.getLimit());
        //2.总的页数  查总的数量  Math.ceil(总数量/pageSize)
        int totalCount = banjiDao.selectTotalCount();*/
        /*LayUITableResult layUITableResult =new LayUITableResult();
        layUITableResult.setCode(0);
        layUITableResult.setCount(totalCount);
        layUITableResult.setData(list);*/
        /*return LayUITableResult.ok(totalCount, list);
    }*/

    @Override
    public void deleteById(int id) {
        banjiDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        //delete from banji where id in(2, 4, 5);
        for (String id : ids) {
            banjiDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Banji banji) {
        banjiDao.add(banji);
    }

    @Override
    public void update(Banji banji) {
        banjiDao.update(banji);
    }

    @Override
    public Banji selectById(int id) {
        return banjiDao.selectById(id);
    }

}
